package com.yourname.myapplication.data.repository

import com.yourname.myapplication.data.local.Dao.QuestionDao
import com.yourname.myapplication.data.local.entity.QuestionEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first

class QuestionRepository(private val dao: QuestionDao) {
    // 获取所有题目（Flow实现实时更新）
    fun getAllQuestions(): Flow<List<QuestionEntity>> = dao.getAll()

    // 插入测试数据
    suspend fun initSampleData() {
        if (dao.getAll().first().isEmpty()) {
            dao.insert(
                QuestionEntity(
                    text = "Android的官方语言是？",
                    options = listOf("Java", "Kotlin", "C++"),
                    answer = 1,
                    explanation = "Google在2019年宣布Kotlin为首选语言"
                )
            )
        }
    }
}